package com.shjy.driver.adapter;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.shjy.driver.R;
import com.shjy.driver.base.ParkingBaseAdapter;

import java.util.List;

/**
 * Created by zhouhuiming on 16/11/17.
 */

public class BlueToothDeviceAdapter extends ParkingBaseAdapter<BluetoothDevice> {
    private int selectPos = -1;
    private int connectPos = -1;

    public BlueToothDeviceAdapter(Context context,List<BluetoothDevice> list) {
        this.context = context;
        this.list = list;
    }

    public int getConnectPos() {
        return connectPos;
    }

    public void setConnectPos(int connectPos) {
        this.connectPos = connectPos;
    }

    public int getSelectPos() {
        return selectPos;
    }

    public void setSelectPos(int selectPos) {
        this.selectPos = selectPos;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if(view == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_bluetooth_device,null);
        }

        BluetoothDevice bluetoothDevice = list.get(i);
        TextView textViewDeviceName = getAdapterView(view,R.id.textViewDeviceName);
        textViewDeviceName.setText((bluetoothDevice.getName()!=null?bluetoothDevice.getName():"T7 BT Printer")+"["+bluetoothDevice.getAddress()+"]");
        ImageView imageViewLink = getAdapterView(view,R.id.imageViewLink);
        if(connectPos == i){
            imageViewLink.setVisibility(View.VISIBLE);
        }else {
            imageViewLink.setVisibility(View.GONE);
        }

        if(selectPos == i){
            view.setPressed(true);
            view.setBackgroundColor(context.getResources().getColor(R.color.color_click_blue));
        }else {
            view.setPressed(false);
            view.setBackgroundColor(context.getResources().getColor(android.R.color.transparent));
        }
        return view;
    }
}
